﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Azad.BCL;
using BCL.Entity;
using NazSoft.Framework;

namespace BCL.Repository
{
    public class LookUpRepository
    {

        public List<Theme> GetAllTheme()
        {
            String cacheKey = "GetAllTheme";
            var data = CacheHelper.Get<List<Theme>>(cacheKey);

            if (data == null)
            {
                data = GetAllThemeFromDatabase();
                CacheHelper.Add(data, cacheKey);
            }

            return data;
        }

        public List<Theme> GetAllThemeFromDatabase()
        {
            object[] objName = null;
            object[] objValue = null;

            SqlHelper helpclass = new SqlHelper();
            DataTable dataTable = helpclass.GetDataTable("GetAllThemes", objName, objValue);
            var lstLookup = CollectionHelper.ConvertTo<Theme>(dataTable).ToList();

            return lstLookup;
        }


        public List<LookUp> GetMenu(string url)
        {
            String cacheKey = "Menu_" + url;
            var data = CacheHelper.Get<List<LookUp>>(cacheKey);

            if (data == null)
            {
                data = GetMenuFromDatabase(url);
                CacheHelper.Add(data, cacheKey);
            }

            return data;
        }

        public List<LookUp> GetMenuFromDatabase(string url)
        {
            object[] objName = { "Url" };
            object[] objValue = { url ?? "" };

            SqlHelper helpclass = new SqlHelper();
            DataTable dataTable = helpclass.GetDataTable("GetMenu", objName, objValue);
            var lstLookup = CollectionHelper.ConvertTo<LookUp>(dataTable).ToList();

            return lstLookup;
        }


        public List<LookUp> GetLookUp(string code)
        {
            String cacheKey = "Menu_" + code;
            var data = CacheHelper.Get<List<LookUp>>(cacheKey);

            if (data == null)
            {
                data = GetLookUpFromDatabase(code);
                CacheHelper.Add(data, cacheKey);
            }

            return data;
        }

        public List<LookUp> GetLookUpFromDatabase(string code)
        {
            object[] objName = { "Code" };
            object[] objValue = { code };

            SqlHelper helpclass = new SqlHelper();
            DataTable dataTable = helpclass.GetDataTable("Get_LookUpByCode", objName, objValue);
            var lstLookup = CollectionHelper.ConvertTo<LookUp>(dataTable).ToList();

            return lstLookup;
        }
    }
}
